package com.tianmenguide.wxapi;

import com.github.pagehelper.Page;
import com.tianmenguide.common.core.domain.AjaxResult;
import com.tianmenguide.guide.domain.AgriculturalProducts;
import com.tianmenguide.guide.domain.Banners;
import com.tianmenguide.guide.domain.TravelGuides;
import com.tianmenguide.guide.service.IAgriculturalProductsService;
import com.tianmenguide.guide.service.IBannersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.tianmenguide.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/wxapi")
@RequiredArgsConstructor
@Api(tags = "农产品wxapi")
public class WxAgriculturalProductsController {

    private final IAgriculturalProductsService agriculturalProductsService;

    @ApiOperation("查询农产品列表")
    @GetMapping("/loadAgriculturalProducts")
    public AjaxResult loadAgriculturalProducts(AgriculturalProducts agriculturalProducts){
        startPage();
        List<AgriculturalProducts> agriculturalProductsList = agriculturalProductsService.selectAgriculturalProductsList(agriculturalProducts);
        Page<AgriculturalProducts> page = (Page<AgriculturalProducts>) agriculturalProductsList;
        int total = page.getPages();
        Map<String, Object> result = new HashMap<>();
        result.put("total", total);
        result.put("data", agriculturalProductsList);
        return AjaxResult.success(result);
    }

    /**
     * 获取农产品管理详细信息
     */
    @ApiOperation("获取农产品管理详细信息")
    @GetMapping(value = "/loadAgriculturalProduct/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(agriculturalProductsService.selectAgriculturalProductsById(id));
    }
}
